import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import AutoImport from 'unplugin-auto-import/vite';
import Components from 'unplugin-vue-components/vite';
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';
import path from 'path'; // 引入 path 模块
export default defineConfig({
  plugins: [
    vue(),
    AutoImport({
      imports: ['vue', 'vue-router'], // 自动导入 Vue 和 Vue Router API
      dts: 'src/auto-imports.d.ts', // 生成类型声明文件
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
  ],
  server: {
    hmr: true,
    host: '0.0.0.0',
    port: 5174,
    // 代理设置
    proxy: {
      // '/api/node': {
      //   changeOrigin: true,
      //   target: 'http://localhost:3000', // 测试环境
      //   rewrite: (path) => path.replace(/^\/api\/node/, '/')
      // },
      '/api': {
        changeOrigin: true,
        // target: 'http://172.16.0.74:8088', // 测试环境
        target: 'http://172.16.60.50:8001', // 测试环境
        rewrite: (path) => path.replace(/^\/serve/, '/')
      }
    }
  },
  resolve: {
    alias: {
      '@': path.resolve(__dirname, './src'), // 设置 @ 指向 src 目录
    },
  },
});
